#include "appeal.h"
#include "ui_appeal.h"
#include<QMessageBox>
#include"appealcheck.h"
#include<QListWidgetItem>
#include<QTime>
#include<QMouseEvent>
appeal::appeal(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::appeal)
{
    ui->setupUi(this);
    this->setWindowFlags(Qt::FramelessWindowHint); // 设置窗口无边框
    ui->textEdit->setPlaceholderText("请输入你的申诉理由,不要超过100个字");
}

appeal::~appeal()
{
    delete ui;
}

void appeal::on_pushButton_3_clicked()
{
    QString content = ui->textEdit->toPlainText();
    if(content == ""){
        // 创建一个QMessageBox对象
        QMessageBox messageBox;
        messageBox.setWindowTitle("警告");
        messageBox.setText("申诉理由不能为空");

        // 设置消息类型
        messageBox.setIcon(QMessageBox::Warning);

        // 添加按钮并设置点击事件处理函数
        QPushButton *okButton = messageBox.addButton(QMessageBox::Ok);

        // 为“Ok”按钮设置点击事件处理函数
        connect(okButton, &QPushButton::clicked, [&]() {
            messageBox.accept();
        });
        // 显示消息框
        messageBox.exec();
    }else{
        QTime current = QTime::currentTime();
        QString currentTimeString = current.toString("HH:mm:ss");
        appealcheck::appealhistory1[appealcheck::appealhistoryNum]="申诉"+ QString::number(appealcheck::appealhistoryNum+1)+" 时间："+currentTimeString+" 状态：未处理";
        appealcheck::appealhistory2[appealcheck::appealhistoryNum]=ui->textEdit->toPlainText();
        appealcheck::appealhistoryNum++;
        this->close();
        // 创建一个QMessageBox对象
        QMessageBox messageBox;
        messageBox.setWindowTitle("提示");
        messageBox.setText("您已申诉成功，将在2个工作日内给您答复");

        // 设置消息类型
        messageBox.setIcon(QMessageBox::Information);

        // 添加按钮并设置点击事件处理函数
        QPushButton *okButton = messageBox.addButton(QMessageBox::Ok);

        // 为“Ok”按钮设置点击事件处理函数
        connect(okButton, &QPushButton::clicked, [&]() {
            messageBox.accept();
        });

        // 显示消息框
        messageBox.exec();
    }

}

void appeal::on_pushButton_2_clicked()
{
    this->close();
}

void appeal::mousePressEvent(QMouseEvent *event) {
    if (event->button() == Qt::LeftButton) {
                initialMousePosition = event->globalPos(); // 记录鼠标按下时的全局位置
                isDragging = true; // 开始拖动
            }
    }

void appeal::mouseMoveEvent(QMouseEvent *event){
    if (isDragging && event->buttons() & Qt::LeftButton) {
                QPoint delta = event->globalPos() - initialMousePosition; // 计算鼠标移动的距离
                move(x() + delta.x(), y() + delta.y()); // 根据鼠标移动的距离来移动窗口
                initialMousePosition = event->globalPos(); // 更新鼠标位置
            }
    }
void appeal::mouseReleaseEvent(QMouseEvent *event) {
        if (event->button() == Qt::LeftButton) {
            isDragging = false; // 结束拖动
        }
    }
